import request from '@/utils/request'
import axios from 'axios'
// 获取OSS上传签名
// 获取hr的token塞入 过期就重新获取，有了就不获取
export async function getOSSParam(data?: any) {
  return request({
      url: '/admin/third/get_oss_upload_param',
      method: 'post',
      data
  })
  const res = await axios({
    url: 'http://hr-api.leyou868.com/admin/third/get_oss_upload_param',
    method: 'POST',
    data,
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${localStorage.getItem('hrToken')}`,
    },
  })
  if (res.data.code !== 0) {
    await getHRToken()
    return getOSSParam(data)
  }
  return res.data
}

async function getHRToken() {
  const res = await axios({
    url: 'http://hr-api.leyou868.com/admin/login',
    method: 'POST',
    data: {
      name: 'token',
      password: 'qq258258258',
    },
    headers: {
      'Content-Type': 'application/json',
    },
  })
  localStorage.setItem('hrToken', res.data.data)
}
export function uploadOss(data?: any) {
  return request({
    url: '/admin/third/upload',
    method: 'post',
    data,
  })
}
